package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.mapper.MessageMapper;
import com.cyzy.pojo.ChatMessage;
import com.cyzy.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cuncun
 * @create 2025-06-03 上午9:58
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper,ChatMessage> implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<ChatMessage> chatHistory(String conversationId) {
        LambdaQueryWrapper<ChatMessage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChatMessage::getConversationId,conversationId);
        List<ChatMessage> chatMessages = messageMapper.selectList(wrapper);
        return chatMessages;
    }

    @Override
    public void saveChatHistory(ChatMessage chatMessage) {
        messageMapper.insert(chatMessage);
        System.out.println(chatMessage.getMessageId());

    }
}
